
// wexin
// wechat
// wxapp
// weapp

Page({
  data: {
    todo: [],
    msg: ''
  },
  onLoad() {
    this.getTodoList()
  },
  inputChange(event) {
	  // console.log(event)
    this.setData({
      msg: event.detail
    })
  },
  linkTo(event) {
	  const { url } = event.currentTarget.dataset
	  console.log(url)
	// console.log(this)
	  wx.navigateTo({url})
  },
  createTodo() {
    const self = this
    if (this.data.msg) {
      wx.request({
        url: 'https://api.yizhanketang.cn/api/v1/todos',
        method: 'POST',
        data: {
          content: this.data.msg
        },
        success(res) {
          self.setData({
            msg: ''
          })
          self.getTodoList()
        }
      })

    } else {
      wx.showToast({
        title: '不能为空',
        icon: 'none',
        duration: 2000
      })
    }
  },
  getTodoList() {
    const self = this
    wx.showLoading({
      title: '加载中'
    })
    wx.request({
      url: 'https://api.yizhanketang.cn/api/v1/todos',
      method: 'GET',
      success(res) {
        const { data } = res.data
        self.setData({
          todo: data
        })
      },
      fail(res) {

      },
      complete(res) {
        wx.hideLoading()
      }
    })
  }
})
